import React,{FC,ReactElement} from "react";
import {
    Navigate
} from "react-router-dom";

import { useSelectorAuth } from "@/store/slice/auth";
// 1-any
// function Index(props:any) {
//     // 可以通过
//     localStorage.getItem("token") // 判断是否登录
//     if(localStorage.getItem("token")){
//         return props.children;
//     }
//     return (
//         <Navigate to={"/login"}/>
//     )
//     return
//     localStorage.getItem("token")?props.children:<Navigate to={"/login"}/>
// }

// // type指定类型
// type TProps ={
//     children:ReactElement
// }
// function Index(props:TProps){
//     return
//     localStorage.getItem("token")?props.children:<Navigate to={"/login"}/>
// }


// // 3-赋值
// type TProps ={
//     children:ReactElement
// }
// const AuthComponent:FC<TProps> = props=>localStorage.getItem("token")?props.children:<Navigate to={"/login"}/>;


// 4- 赋值 any
const AuthComponent:FC<any> = props=>{
    const auth = useSelectorAuth();
    return auth.token?props.children:<Navigate to={"/login"}/>
}
export default AuthComponent;